<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>门店管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			yzAreaName();
			checkSize();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{          
					remarks:{remarkCheck:true} ,
					name:{required:true,stringCheck:true,areaName:true} 
					
	            },
	            
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			jQuery.validator.addMethod("stringCheck", function(value, element) {
				return this.optional(element) || /^[\u4e00-\u9fa5]{2,10}$/.test(value);
			}, "请输入2-10个汉字");
			
			jQuery.validator.addMethod("remarkCheck", function(value,  
	                element, param) { 
				if(value.length>100){
					return false;
				} else{
					return true;
	            }
	        }, $.validator.format("字数超限"));
			$("#remarks").keyup(function(){
				checkSize();
			})
			
			jQuery.validator.addMethod("areaName", function(value,  
	                element, param) { 
				   var stg=$("#stgs").val();
				   if(stg==1){
					   return false;
				   }else{
					   return true;
				   }
				    
	        }, $.validator.format("区域名称重复"));
			
		});
		function checkSize(){
			var curLength=$("#remarks").val().length;
			if(curLength>100){
				$("#textLength").css("color","red");
				$("#textLength").text(curLength+"/100");
			}else{
				$("#textLength").css("color","");
				$("#textLength").text(curLength+"/100");
			}
		}
		
		function yzAreaName(){
			var name=$("#name").val();
			var id=$("#areaId").val();
			 $.ajax({
			    	type:"post",
			    	data:{"name":name,"id":id},
			    	dataType:"json",
			    	url:"${ctx}/sys/store/yzAreaName",
			    	success:function(data){
			    		if(data.st==1){
			    			$("#stgs").val(1)
			    		}else{
			    			$("#stgs").val(0)
			    		}
			    	}
			    })
		}
	</script>
</head>
<body>
     <input name="stgs" id="stgs" type="hidden"/>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/store/storeAreaList">门店区域管理列表</a></li>
		<li class="active"><a href="${ctx}/sys/store/areaForm?id=${area.id}">门店区域管理<shiro:hasPermission name="sys:store:edit">${not empty area.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:store:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="area" action="${ctx}/sys/store/areaSave" method="post" class="form-horizontal">
		<form:hidden path="id" id="areaId"/>
		<sys:message content="${message}"/>	
		<input name="parent" type="hidden" value="0">	
		<div class="control-group ">
			<label class="control-label ">区域名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="30" class="input-xlarge required" id="name" onchange="yzAreaName()"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">区域描述：</label>
			<div class="controls">
			    <span id="textLength" style="margin-top: 74px;position: absolute;line-height: 1; margin-left: 475px;color: red;">0/100</span>
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="22511" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:store:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>